﻿using Microsoft.AspNetCore.Mvc;
using mozhi.smarterp.Finance.Querys;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp;

namespace mozhi.smarterp.Finance.Reports
{
    [RemoteService]
    [Route("api/v1/reports")]
    public class ReportController : BaseController
    {
        private IFinancialReportItemAppService _financialReportItemAppService;
        private IAccountBalanceReportAppService _accountBalanceReportAppService;
        private ISubsidiaryledgerReportAppService _subsidiaryledgerReportAppService;
        private IGeneralledgerReportAppService _generalledgerReportAppService;
        private IIncomeStatementReportAppService _incomeStatementReportAppService;
        private ICashflowStatementReportAppService _cashflowStatementReportAppService;
        private IBalanceSheetReportAppService _balanceSheetReportAppService;

        public ReportController(IFinancialReportItemAppService financialReportItemAppService, 
            IAccountBalanceReportAppService accountBalanceReportAppService,
            ISubsidiaryledgerReportAppService subsidiaryledgerReportAppService,
            IGeneralledgerReportAppService generalledgerReportAppService,
            IIncomeStatementReportAppService incomeStatementReportAppService,
            ICashflowStatementReportAppService cashflowStatementReportAppService,
            IBalanceSheetReportAppService balanceSheetReportAppService)
        {
            _financialReportItemAppService = financialReportItemAppService;
            _accountBalanceReportAppService = accountBalanceReportAppService;
            _subsidiaryledgerReportAppService = subsidiaryledgerReportAppService;
            _generalledgerReportAppService = generalledgerReportAppService;
            _incomeStatementReportAppService = incomeStatementReportAppService;
            _cashflowStatementReportAppService = cashflowStatementReportAppService;
            _balanceSheetReportAppService = balanceSheetReportAppService;
        }


        [HttpGet]
        [Route("items")]
        public async Task<List<FinancialReportItemDto>> GetReportItemsAsync(FinancialReportItemQuery query)
        {
            var result = await _financialReportItemAppService.FindAsync(query);

            return result;
        }

        [HttpPut]
        [Route("items")]
        public async Task<List<FinancialReportItemDto>> UpdateReportItemAsync(List<FinancialReportItemUpdateDto> dtos)
        {
            var result = await _financialReportItemAppService.UpdateAsync(dtos);

            return result;
        }

        [HttpDelete]
        [Route("items/{id}")]
        public async Task DeleteItemAsync(Guid id , List<Guid> settingIds)
        {
            await _financialReportItemAppService.DeleteAsync(id, settingIds);
        }


        [HttpPost]
        [Route("accountbalance")]
        public async Task<List<AccountBalanceReportDto>> GetAccountBalanceReportDataAsync(ReportQueryBase query)
        {
            var result = await _accountBalanceReportAppService.GetData(query);

            return result;
        }

        [HttpPost]
        [Route("subsidiaryledger")]
        public async Task<List<SubsidiaryledgerReportDto>> GetSubsidiaryLedgerReportDataAsync(ReportQueryBase query)
        {
            var result = await _subsidiaryledgerReportAppService.GetData(query);

            return result;
        }

        [HttpPost]
        [Route("generalledger")]
        public async Task<List<GeneralledgerReportDto>> GetGeneralledgerReportDataAsync(ReportQueryBase query)
        {
            var result = await _generalledgerReportAppService.GetData(query);

            return result;
        }


        [HttpPost]
        [Route("incomestatement")]
        public async Task<List<IncomeStatementReportDto>> GetIncomeStatementDataAsync(IncomeStatementReportQuery query)
        {
            var result = await _incomeStatementReportAppService.GetData(query);

            return result;
        }

        [HttpPost]
        [Route("balancesheet")]
        public async Task<List<BalanceSheetReportDto>> GetBalanceSheetDataAsync(BalanceSheetReportQuery query)
        {
            var result = await _balanceSheetReportAppService.GetData(query);

            return result;
        }

        [HttpPost]
        [Route("cashflowstatement")]
        public async Task<List<CashflowStatementReportDto>> GetCashflowStatementDataAsync(CashflowStatementReportQuery query)
        {
            var result = await _cashflowStatementReportAppService.GetDataAsync(query);

            return result;
        }
    }
}
